from flask import Flask,render_template,request,redirect,session,escape
app = Flask(__name__)
app.secret_key = '123456'

@app.route('/')
@app.route('/entry')
def entry01() -> 'html':
    title = '登录系统'
    return render_template('entry.html',
                           the_title = "登陆系统")

@app.route('/login',methods=['GET',"POST"])
def login():
    if request.method == 'GET':
     return render_template('login.html')
    #request.args
    user = request.form.get('user')
    pwd = request.form.get('pwd')
    if user == 'hh' and pwd == '123':
        session['user_info'] = user
        return redirect('/index')
    else:
        return render_template('login.html',**{'msg':'用户名或密码错误'})
        #return render_template('login.html', msg='用户名或密码错误')

@app.route('/index')
def index():
#    if session.get():
     return "登陆成功"

@app.route('/viewlog')
def view_the_log() -> 'html':
    contents = []
    with open('car.log','r') as log:
        for line in log:
            contents.append([])
            for item in line.split('|'):
                contents[-1].append(escape(item))
    len(contents)
    titles = ('用户提交','远程地址','访问代理','用户结果')
    return render_template('log.html',
                           the_title='日志系统后台',
                           the_row_title=titles,
                           the_data=contents)


if __name__ == '__main__':
    app.run(debug=True)